.TH std::list::push_front 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::list::push_front \- std::list::push_front

.SH Synopsis
   void push_front( const T& value ); \fB(1)\fP
   void push_front( T&& value );      \fB(2)\fP \fI(since C++11)\fP

   Prepends the given element value to the beginning of the container.

   No iterators or references are invalidated.

.SH Parameters

   value - the value of the element to prepend

.SH Return value

   \fI(none)\fP

.SH Complexity

   Constant.

.SH Exceptions

   If an exception is thrown for any reason, these functions have no effect (strong
   exception safety guarantee).

.SH Example


// Run this code

 #include <list>
 #include <iomanip>
 #include <iostream>
 #include <string>

 int main()
 {
     std::list<std::string> letters;

     letters.push_front("abc");
     std::string s{"def"};
     letters.push_front(std::move(s));

     std::cout << "std::list letters holds: ";
     for (auto&& e : letters)
         std::cout << std::quoted(e) << ' ';

     std::cout << "\\nMoved-from string s holds: " << std::quoted(s) << '\\n';
 }

.SH Possible output:

 std::list letters holds: "def" "abc"
 Moved-from string s holds: ""

.SH See also

   emplace_front  constructs an element in-place at the beginning
   \fI(C++11)\fP        \fI(public member function)\fP
   push_back      adds an element to the end
                  \fI(public member function)\fP
   pop_front      removes the first element
                  \fI(public member function)\fP
                  creates a std::front_insert_iterator of type inferred from the
   front_inserter argument
                  \fI(function template)\fP
